﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Habito.Solutions
{
	public partial class Index : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!string.IsNullOrEmpty(Request.QueryString["id"]))
			{
				ViewState["id"] = Request.QueryString["id"];
			}

			Ajax.BLL.Solutions solution = new Ajax.BLL.Solutions();
			Ajax.BLL.SolutionClass solutionClass = new Ajax.BLL.SolutionClass();
			List<Ajax.Model.SolutionClass> classes = solutionClass.GetModelList("");

			//<h3 class="menuheader expandable" style="color: Black; background-image: url('../../Content/Images/doc_title.png')));">
			//        Solution Test</h3>
			//    <ul class="categoryitems">
			//        <li>
			//            <a href="#">Horizontal CSS Menus</a></li>
			//        <li>
			//            <a href="#">Vertical CSS Menus</a></li>
			//        <li>
			//            <a href="#">Image CSS</a></li>
			//        <li>
			//    </ul>
			StringBuilder result = new StringBuilder();
			foreach (var item in classes)
			{
				result.AppendFormat("<h3 class=\"menuheader expandable\" style=\"color: Black; background-image: url('../../Content/Images/doc_title.png')));\">{0}</h3>", item.ClassName);
				List<Ajax.Model.Solutions> lists = solution.GetModelList(" ClassID = " + item.ID);
				if (lists != null && lists.Count > 0)
				{
					result.Append("<ul class=\"categoryitems\">");
				}
				foreach (var items in lists)
				{
					string sss = items.Title;
					if (items.Title.Length > 55)
					{
						items.Title = items.Title.Substring(0, 55) + "...";
					}
					result.AppendFormat("<li><div class='link' title='{2}' style='cursor:pointer' tt='1' myid = '{1}'>{0}</div></li>", items.Title, items.ID, sss);
				}
				if (lists != null && lists.Count > 0)
				{
					result.Append("</ul>");
				}
			}
			ViewState["solutions"] = result.ToString();
		}

		protected override void OnInit(EventArgs e)
		{
			if (Request.QueryString["GetContent"] == "1")
			{
				int id = int.Parse(Request.QueryString["id"]);
				Ajax.BLL.Solutions solution = new Ajax.BLL.Solutions();
				Ajax.Model.Solutions solutions = solution.GetModel(id);
				if (solutions != null)
				{
					Response.Write(solutions.Description);
					Response.End();
				}
			}
			base.OnInit(e);
		}
	}
}